﻿using ChinaMobile;
using ChinaMobile.XinJu;
using Coder.Workflow;
using Fee.MingTong;
using Fee.Orders;
using Fee.Orders.AuthProjectWorkflow;
using Fee.Orders.DesignWorkflow;
using Fee.Orders.FormalWorkflow;
using Fee.Orders.PreWorkflow;
using Fee.Stores;
using Fee.Stores.Ef;
using Fee.Sync;
using Identity.Stores;
using Identity.Stores.Ef;
using Microsoft.Extensions.DependencyInjection;
using MySql.Data.MySqlClient;

namespace Fee.Extentions
{
    public static class FeeExtentions
    {
        public static IServiceCollection AddFeeServices<T>(this IServiceCollection services, string xinJuConnection)
            where T : FeeDbContext
        {
            services.AddScoped<IVendorMatcherStore<T>, VendorMatcherStore<T>>()
                .AddScoped<IFrameworkContractStore<T>, FrameworkContractStore<T>>()
                .AddScoped<IStationStore<T>, StationStore<T>>()
                .AddScoped<IDistrictStore<T>, DistrictStore<T>>()
                .AddScoped<IVendorStore<T>, VendorStore<T>>()
                .AddScoped<IProjectStore<T>, ProjectStore<T>>()
                .AddScoped<IConstructionTaskStore<T>, ConstructionTaskStore<T>>()
                .AddScoped<IBudgetOrderStore<T>, BudgetOrderStore<T>>()
                .AddScoped<IPreDelegateOrderStore<T>, PreDelegateOrderStore<T>>()
                .AddSingleton<DelegateOrderBatchGenerator>()
                .AddScoped<IFormalOrderStore<T>, FormalOrderStore<T>>()
                .AddScoped<IAuthProjectOrderStore<T>, AuthProjectOrderOrderStore<T>>();
                ;
            ;
            //明通 扩展
            services.AddScoped<MingTongManager>().AddScoped<MingTongWorkOrderManager>();
            // 同步station信息
            services.AddScoped<StationSyncer<T>>().AddScoped<XinJuStationStore>(sp =>
            {
                var mysqlconnection = new MySqlConnection(xinJuConnection);
                return new XinJuStationStore(mysqlconnection);
            });

            //扩展工作流
            services.AddScoped<BudgetOrderManager<T>>();
            services.AddScoped<FormalOrderManager<T>>();
            services.AddScoped<AuthProjectManager<T>>();
            services.AddScoped<PreDelgateOrderManager<T>>();


            //workProcess number generoator
            services.AddSingleton<WorkflowNumberGenerator, FeeWorkflowNumberGenerator>();

            //file attach
        

            return services;
        }
    }
}